#include<bits/stdc++.h>

#define rp(i,a,b) for(int i=a;i<b;++i)
#define rrp(i,b,a) for(int i=b;i>=a;--i)

using namespace std;

int main(){
	int n,m;scanf("%d%d", &n,&m);
	int chessBoard[n][m];
	rp(i , 0 , n) rp(j , 0 , m) scanf("%d", &chessBoard[i][j]);
	int verticalTag[n][m],horizontalTag[n][m];
	rp(i , 0 , n) rp(j , 0 , m){
		verticalTag[i][j] = 0;
		horizontalTag[i][j] = 0;
	}
	rp(i , 0 , n) rp(j , 0 , m){
		int k = j + 1;
		while(k < m && chessBoard[i][k] == chessBoard[i][j]) ++k;
		if(k - j > 2){
			rp(x , j , k) horizontalTag[i][x] = 1;
		}
		j = k - 1;
	}

	rp(i , 0 , m) rp(j , 0 , n){
		int k = j + 1;
		while(k < n && chessBoard[k][i] == chessBoard[j][i]) ++k;
		if(k - j > 2){
			rp(x , j , k) verticalTag[x][i] = 1;
		}
		j = k - 1;
	}

	rp(i , 0 , n) rp(j , 0 , m){
		if(verticalTag[i][j] == 1 || horizontalTag[i][j] == 1){
			printf("0%c", j == m-1?'\n':' ');
		}else{
			printf("%d%c", chessBoard[i][j], j == m-1?'\n':' ');
		}
	}
	
	return 0;
}